package org.csu.agrisupply.api.controller.front;

import org.csu.agrisupply.api.common.CommonResponse;
import org.csu.agrisupply.api.entity.RC;
import org.csu.agrisupply.api.service.RCService;
import org.csu.agrisupply.api.vo.RCVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/RC/")
public class RCController {
    @Autowired
    private RCService rcService;
    //得到所有合作社
    @GetMapping("")
    @ResponseBody
    public CommonResponse<List<RCVo>> getRCList(){
        return rcService.getRCList();
    }
    //得到单个合作社
    @GetMapping("{rcId}")
    @ResponseBody
    public CommonResponse<RCVo> getRC(@PathVariable("rcId") String rcId){

        return rcService.getRC(rcId);
    }
    //修改合作社信息
    @PutMapping("{rcId}")
    @ResponseBody
    public CommonResponse<RC> updateRC(@PathVariable("rcId") String rcId ,
                                       @RequestBody RC rc){
       return rcService.updateRC(rcId,rc);
    }
    //注册合作社
    @PostMapping("users/{userId}")
    @ResponseBody
    public CommonResponse<RC> registerRC(@PathVariable("userId") String userId,
                                         @RequestBody RC rc){
        return rcService.registerRC(userId,rc);
    }
    //邀请其他用户加入合作社
    @PutMapping("users/{userId}")
    @ResponseBody
    public CommonResponse<RC> inviteUsertoRC(@PathVariable("userId") String userId,
                                             @RequestParam(value = "inviteUserId",required = true)String inviteUserId){
        return rcService.inviteUsertoRC(userId,inviteUserId);
    }
    //根据userId查询合作社
    @GetMapping("users/{userId}")
    @ResponseBody
    public CommonResponse<RCVo> getRCbyUserId(@PathVariable("userId") String userId){
        return rcService.getRCbyUserId(userId);
    }

}
